/** @odoo-module **/
import {
    Component,
    onMounted,
    mount,
    xml,
    useEnv,
    App,
    useSubEnv,
    reactive,
    useState,
    markup, useRef,
  } from "@odoo/owl";
 
  import { loadBundle } from "@web/core/assets";
  import { rpc } from "@web/core/network/rpc";
  const { DateTime } = luxon;
import { registry } from "@web/core/registry";
import { useService ,useOwnedDialogs} from "@web/core/utils/hooks";
import { usePopover } from "@web/core/popover/popover_hook";
import { bootsrap001 } from "./bootsrap001";
import { websocketshili } from "./websoketshili";
import { vueshili } from "./vueshili";
import { kouzishili } from "./kouzishili";
export class shili1 extends Component {
    
    static template = xml`
    <div t-ref="root">
            <button  t-ref="boot001"  t-on-mouseenter="bootstrap1" >bootstrap</button>
             <button    t-on-click="gantetu" >甘特图示例</button>
             <button    t-on-click="shenpi" >审批示例</button>       
               <button    t-on-click="chongxiefields_get" >动态生成字段</button>    
                         <button    t-on-click="riqibijiao" >日期比较</button>          
                              <button    t-on-click="mocheng" >动态加载资产</button>     
                                       <button    t-on-click="pythondaoru" >测试python导入</button>  
    <button    t-on-click="websocketclick" >websocket</button>  
        <button    t-on-click="vue" >odoo集成流程设计器</button>  
     <button    t-on-click="kouzi" >odoo集成rect框架 开源扣子</button>  
                                       </div>
`;
     setup() {
        this.boot001 = useRef("boot001");
        this.popover2= usePopover(bootsrap001, {});
        this.popover3= usePopover(websocketshili, {});
        this.popover4= usePopover(vueshili, {});
        this.popover5= usePopover(kouzishili, {});
        this.action = useService("action");
        this.r1 = useRef("root");
     }
     async bootstrap1() {
        this.popover2.open(this.boot001.el, {});
      }
      async pythondaoru() {
        try {
          // 调用后端控制器路由
          const response = await rpc("/my_module/get_data");
          if (response.status === 'success') {
              console.log("获取的数据:", response.data);
              // 这里使用 response.data ("这是来自abc.py的变量值")
          }
      } catch (error) {
          console.error("调用失败:", error);
      }
      }
      async gantetu() {
        console.log("你有本事断住我吗222？");
        this.action.doAction({
          type: 'ir.actions.act_window',
          name: '任务甘特图',
          res_model: 'gantt.task',
          view_mode: 'gantt,list',
          views: [[false, 'gantt'],[false, 'list']]
      });
      }
      async shenpi() {
        this.action.doAction({
          type: 'ir.actions.act_window',
          name: '审批示例',
          res_model: 'qingjiadan',
          view_mode: 'list,form',
          views: [[false, 'list'],[false, 'form']]
        })
      }
    async mocheng(){
      await loadBundle("spreadsheet.o_spreadsheet");
      
      console.log(odoo.loader.modules.get("@spreadsheet/components/share_button/share_button").SpreadsheetShareButton);
    }

      async riqibijiao() {
        const date1 = DateTime.fromISO('2025-05-20');
        const date2 = DateTime.now();
        console.log(date1,date2);
        if (date1 < date2) {
            console.log("date1 是过去的日期");
        } else {
            console.log("date1 是未来的日期");
        }
      }
      async websocketclick() {
        this.popover3.open(this.r1.el);
      }
      async vue() {
        this.popover4.open(this.r1.el);
      }
           async kouzi() {
        this.popover5.open(this.r1.el);
      }
      async chongxiefields_get() {
        this.action.doAction({
          type: 'ir.actions.act_window',
          name: '动态生成字段',
          res_model: 'shilimokuai002.noziduan',
          view_mode: 'list,form',
          target: 'new',
          views: [[false, 'list'],[false, 'form']]
        })
      }
  }
  shili1.components = {
 
  };
  shili1.props = {
    "*":true
  }


registry.category("actions").add("shili1", shili1);